package com.authine.cloudpivot.web.api.controller;

import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.service.ErpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "刷新人员薪资接口", tags = "erp相关接口")
@RestController
@RequestMapping("/api/erpCloudpivot")
@Slf4j
public class ErpController extends BaseController {

    @Autowired
    private ErpService erpService;

    @ApiOperation(value = "erp数据刷新接口" )
    @GetMapping("/flushErpData")
    public Map<String, String> flushErpData(){
        List<Map<String, String>> subjectList = erpService.getSubjectList();
        Map<String, Map<String, String>> maps = new HashMap<>();
        for (Map<String, String> map : subjectList) {
            Map<String, String> subjectData = new HashMap<>();
            subjectData.putAll(map);
            maps.put(MapUtils.getString(map,"customerCode"),subjectData);
        }
        erpService.updateSalaryPay(maps);
        return null;
    }
}
